﻿using AntMovement.Core.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.PCI9016.Domain
{
    public class HardwareUpdateDO : AntMovement.Core.IHardwareUpdate
    {
        private List<DO> _values = new List<DO>();
        private ulong _nCardNo;

        public HardwareUpdateDO(ulong nCardNo, DO[] values)
        {
            _nCardNo = nCardNo;
            _values.AddRange(values);
        }

        public string Update()
        {
            uint data = 0;
            long error = PCI9016.p9016_get_do((int)_nCardNo, ref data);
            if (error != 0) { return $"CardNo[{_nCardNo}] p9016_get_do ==>> {(PCI9016Error)error}"; }
            int i = 0;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 1;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 2;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 3;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 4;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 5;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 6;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 7;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 8;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 9;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 10;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 11;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 12;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 13;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 14;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 15;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            return "ok";
        }
    }
}
